//
//  topView.swift
//  我的微博
//
//  Created by 杨庆 on 15/10/25.
//  Copyright © 2015年 双元班. All rights reserved.
//

import UIKit
import SDWebImage
/// 微博 cell 的顶部
class topView: UIView {
    /// 微博模型数据
    var statuses: status?{
        didSet{
        if let url = statuses?.user?.imageURL {
            iconView.sd_setImageWithURL(url)
        }
        vipIconView.image = statuses?.user?.vipImage
        nameLabel.text = statuses?.user?.name ?? ""
        memberIconView.image = statuses?.user?.memberImage
            
        timeLabel.text = "刚刚"
        sourceLabel.text = "来自 weibo.com"
        }
    }
    //MARK:-懒加载界面;
    override init(frame: CGRect) {
        super.init(frame: frame)
//        backgroundColor = UIColor.yellowColor()
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    /// 添加界面
    private func setupUI(){
        //0.添加顶部的分割视图
        let sepview = UIView()
        sepview.backgroundColor = UIColor(white: 0.90, alpha: 1)
        addSubview(sepview)
        sepview.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        //1.添加界面
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        //2.设置布局
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: sepview, size: CGSizeMake(35, 35), offset: CGPoint(x: statusCellControlMargin, y: statusCellControlMargin))
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLabel, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        memberIconView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        vipIconView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: statusCellControlMargin, y: statusCellControlMargin))
    }
    //MARK:-懒加载控件;
    //借助了 extension 的扩展的方法和方式来进行的创建;
    //1.头像图标
    private lazy var iconView = UIImageView()
    //2.姓名
    private lazy var nameLabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    //3.时间标签
    private lazy var timeLabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    //4.来源标签
    private lazy var sourceLabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    //5.会员图标
    private lazy var memberIconView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    //6.vip图标
    private lazy var vipIconView:UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
}
